package com.yun.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yun.pojo.Pet;
import com.yun.service.PetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;


import java.util.List;

/*
@Controller
public class PageHelperController {
    @Autowired
    PetService  petService;

        @RequestMapping("/PageHelper")
        public String PageHelper(Model model,
                        @RequestParam(required = false, defaultValue = "1", value = "pageNum") Integer pageNum,
                                 @RequestParam(defaultValue = "5", value = "pageSize") Integer pageSize) {


            if(pageNum == null){
            pageNum = 1;   //设置默认当前页
            }
            if(pageNum <= 0){
            pageNum = 1;
            }
            if(pageSize == null){
            pageSize = 5;    //设置默认每页显示的数据数
            }
            //1.引入分页插件,pageNum是第几页，pageSize是每页显示多少条,默认查询总数count
           PageHelper.startPage(pageNum,pageSize);
           //2.紧跟的查询就是一个分页查询-必须紧跟.后面的其他查询不会被分页，除非再次调用PageHelper.startPage
        try {
            List<Pet> list = petService.queryPets();
            //3.使用PageInfo包装查询后的结果,5是连续显示的条数,结果list类型是Page<E>
            PageInfo<Pet> pets = new PageInfo(list,pageSize);
            //4.使用model/map/modelandview等带回前端
            model.addAttribute("pageInfo",pets);
        }finally {
            PageHelper.clearPage(); //清理 ThreadLocal 存储的分页参数,保证线程安全
        }
            return "pet/petInfo";
    }
}*/
